package com.karrim.server.io.file;

import com.karrim.server.io.def.LengthLocator;
import com.karrim.server.io.file.def.FileStream;
import java.io.FileInputStream;
import java.io.IOException;

/**
 *
 * @author andrea.cantafio
 */
public class FileLoader extends AbstractFileLoader<Byte[]> {

    public FileLoader() {
    }

    @Override
    public Byte[] tryLoadLocated(FileStream connectable, LengthLocator locable) throws IOException {
        Byte[] b;
        FileInputStream in = connectable.get();
        int available = in.available(), length = locable.get();
        if (available < length) {
            b = new Byte[available];
        } else {
            b = new Byte[length];
        }
        
        return b;
    }
    private int current = 0;
}
